package com.bg.print.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bg.print.dao.UserDao;
import com.bg.print.entity.UserEntity;
import com.bg.print.service.UserService;
import com.bg.print.utils.PageUtils;
import com.bg.print.utils.Query;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserEntity> page = this.page(
                new Query<UserEntity>().getPage(params),
                new QueryWrapper<UserEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 上下文userDetails查找用户数据
     * @param userDetails
     * @return
     */
    @Override
    public UserEntity getUserByUserDetails(UserDetails userDetails) {
        LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserEntity::getAccount, userDetails.getUsername());
        UserEntity userEntity = this.baseMapper.selectOne(queryWrapper);
        userEntity.setPassword(null);
        userEntity.setEnabled(null);
        userEntity.setPermissions(null);
        return userEntity;
    }
    @Transactional
    @Override
    public Integer updateByAccount(UserEntity user) {



        return null;
    }

}